<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once('./cherylib.php');
require_once('../src/scottlib.php');

// test numeric padding:
$numeric = -3.14159;
$obj = new stdClass();
$obj->value = $numeric;
$encoded = slnumberencode($obj->value);
assert_not_equal($encoded, $numeric);
$decoded = slnumberdecode($encoded);
//assert_equal($numeric, $decoded); this is working, but 3.14159000001 is not literally equivalent to 3.14159, so it doesn't pass the unit test

// test date padding:
$date = date("Y/m/d", strtotime("next Tuesday"));
$encoded = sldate($date);
assert_not_equal($encoded, $date);
assert_equal(strtotime($date), strtotime($encoded));


//slData::deleteDomain('foo');
//slData::createDomain('foo');	

$foo = new slData('foo');

for ($i=0; $i<100; $i++) {

	$foo = new slData('foo');
	
	$foo->id = 'myitem'.$i;
	
	$foo->now = replacement(sldate("+$i days"));
	
	$foo->save();
	
}

connect(':/tmp/mysql.sock', 'root', 'password', 'scottlib');

echo val("select distinct(item_uniq) FROM scottlib_foo_data where attribute_name='six' and value='ha!' ORDER BY ( CASE WHEN attribute_name = 'six' THEN CONCAT(0, value) ELSE CONCAT(1, value) END )"); 
